<template>
  <div class="better-scroll" ref="wrapper">
    <div>
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import BScroll from 'better-scroll'
  export default {
    name: "BScroll",
    props:{
      probeType:{
        type:Number,
        default(){
          return 0;
        }
      },
      pullUpLoad:{
        type:Boolean,
        default() {
          return false;
        }
      },
      bounce: {
        type:Boolean,
        default(){
          return true;
        }
      }
    },
    data(){
      return{
        scroll:null,
      }
    },
    mounted() {
      this.scroll = new BScroll(this.$refs.wrapper,{
        observeDOM:true,
        observeImage:true,
        click:true,
        probeType:this.probeType,
        pullUpLoad:this.pullUpLoad,
        bounce:this.bounce,
        disableTouch:false,
      })
      //将滑动到的位置传递到父组件
      this.scroll.on('scroll',(positon)=>{
        this.$emit('scroll',positon)
      })
      if (this.pullUpLoad){
        this.scroll.on('pullingUp',()=> {
          this.$emit('pullingUp')
        })
      }
    },
    methods:{
      scrollto(x,y,time=300){
        this.scroll.scrollTo(x,y)
      },
      finishPullUp() {
        setTimeout(()=>{
          this.scroll && this.scroll.finishPullUp()
        },300)
      },
      getscrollY(){
        return this.scroll ? this.scroll.y : 0
      }
    }

  }
</script>

<style scoped>

</style>